﻿using System.ComponentModel;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using ElevateAVIMotion.Tools;

namespace ElevateAVIMotion.Properties
{
    public class LangProvider : INotifyPropertyChanged
    {
        internal static LangProvider Instance => ResourceHelper.GetResource<LangProvider>("DemoLangs");

        private static string CultureInfoStr;

        public static CultureInfo Culture
        {
            get => Lang.Culture;
            set
            {
                if (value == null) return;
                if (Equals(CultureInfoStr, value.EnglishName)) return;
                Lang.Culture = value;
                CultureInfoStr = value.EnglishName;

                Instance.UpdateLangs();
            }
        }

        public static string GetLang(string key) => Lang.ResourceManager.GetString(key, Culture);

        public static void SetLang(DependencyObject dependencyObject, DependencyProperty dependencyProperty, string key) =>
            BindingOperations.SetBinding(dependencyObject, dependencyProperty, new Binding(key)
            {
                Source = Instance,
                Mode = BindingMode.OneWay
            });

		private void UpdateLangs()
        {
			OnPropertyChanged(nameof(Add));
			OnPropertyChanged(nameof(AxisXY));
			OnPropertyChanged(nameof(Camera));
			OnPropertyChanged(nameof(Cancel));
			OnPropertyChanged(nameof(Confirm));
			OnPropertyChanged(nameof(Date));
			OnPropertyChanged(nameof(Debug));
			OnPropertyChanged(nameof(Delete));
			OnPropertyChanged(nameof(Display));
			OnPropertyChanged(nameof(Edit));
			OnPropertyChanged(nameof(Four));
			OnPropertyChanged(nameof(Help));
			OnPropertyChanged(nameof(Index));
			OnPropertyChanged(nameof(Input));
			OnPropertyChanged(nameof(LangComment));
			OnPropertyChanged(nameof(Language));
			OnPropertyChanged(nameof(List));
			OnPropertyChanged(nameof(Manual));
			OnPropertyChanged(nameof(Move));
			OnPropertyChanged(nameof(Name));
			OnPropertyChanged(nameof(One));
			OnPropertyChanged(nameof(Open));
			OnPropertyChanged(nameof(Operate));
			OnPropertyChanged(nameof(Other));
			OnPropertyChanged(nameof(Position));
			OnPropertyChanged(nameof(ProductNum));
			OnPropertyChanged(nameof(Property));
			OnPropertyChanged(nameof(Remark));
			OnPropertyChanged(nameof(Run));
			OnPropertyChanged(nameof(Save));
			OnPropertyChanged(nameof(Select));
			OnPropertyChanged(nameof(Stop));
			OnPropertyChanged(nameof(Teach));
			OnPropertyChanged(nameof(TeachConfirmString));
			OnPropertyChanged(nameof(Three));
			OnPropertyChanged(nameof(Time));
			OnPropertyChanged(nameof(Two));
			OnPropertyChanged(nameof(Update));
        }

        /// <summary>
        ///   查找类似添加的本地化字符串
        /// </summary>
		public string Add => Lang.Add;

        /// <summary>
        ///   查找类似轴XY的本地化字符串
        /// </summary>
		public string AxisXY => Lang.AxisXY;

        /// <summary>
        ///   查找类似相机的本地化字符串
        /// </summary>
		public string Camera => Lang.Camera;

        /// <summary>
        ///   查找类似取消的本地化字符串
        /// </summary>
		public string Cancel => Lang.Cancel;

        /// <summary>
        ///   查找类似确定的本地化字符串
        /// </summary>
		public string Confirm => Lang.Confirm;

        /// <summary>
        ///   查找类似日期的本地化字符串
        /// </summary>
		public string Date => Lang.Date;

        /// <summary>
        ///   查找类似调试的本地化字符串
        /// </summary>
		public string Debug => Lang.Debug;

        /// <summary>
        ///   查找类似删除的本地化字符串
        /// </summary>
		public string Delete => Lang.Delete;

        /// <summary>
        ///   查找类似显示的本地化字符串
        /// </summary>
		public string Display => Lang.Display;

        /// <summary>
        ///   查找类似编辑的本地化字符串
        /// </summary>
		public string Edit => Lang.Edit;

        /// <summary>
        ///   查找类似四的本地化字符串
        /// </summary>
		public string Four => Lang.Four;

        /// <summary>
        ///   查找类似帮助的本地化字符串
        /// </summary>
		public string Help => Lang.Help;

        /// <summary>
        ///   查找类似序号的本地化字符串
        /// </summary>
		public string Index => Lang.Index;

        /// <summary>
        ///   查找类似输入的本地化字符串
        /// </summary>
		public string Input => Lang.Input;

        /// <summary>
        ///   查找类似查找类似{0}的本地化字符串的本地化字符串
        /// </summary>
		public string LangComment => Lang.LangComment;

        /// <summary>
        ///   查找类似语言的本地化字符串
        /// </summary>
		public string Language => Lang.Language;

        /// <summary>
        ///   查找类似列表的本地化字符串
        /// </summary>
		public string List => Lang.List;

        /// <summary>
        ///   查找类似手动的本地化字符串
        /// </summary>
		public string Manual => Lang.Manual;

        /// <summary>
        ///   查找类似运动的本地化字符串
        /// </summary>
		public string Move => Lang.Move;

        /// <summary>
        ///   查找类似名称的本地化字符串
        /// </summary>
		public string Name => Lang.Name;

        /// <summary>
        ///   查找类似一的本地化字符串
        /// </summary>
		public string One => Lang.One;

        /// <summary>
        ///   查找类似打开的本地化字符串
        /// </summary>
		public string Open => Lang.Open;

        /// <summary>
        ///   查找类似操作的本地化字符串
        /// </summary>
		public string Operate => Lang.Operate;

        /// <summary>
        ///   查找类似其他的本地化字符串
        /// </summary>
		public string Other => Lang.Other;

        /// <summary>
        ///   查找类似点位的本地化字符串
        /// </summary>
		public string Position => Lang.Position;

        /// <summary>
        ///   查找类似料号的本地化字符串
        /// </summary>
		public string ProductNum => Lang.ProductNum;

        /// <summary>
        ///   查找类似属性的本地化字符串
        /// </summary>
		public string Property => Lang.Property;

        /// <summary>
        ///   查找类似备注的本地化字符串
        /// </summary>
		public string Remark => Lang.Remark;

        /// <summary>
        ///   查找类似运行的本地化字符串
        /// </summary>
		public string Run => Lang.Run;

        /// <summary>
        ///   查找类似保存的本地化字符串
        /// </summary>
		public string Save => Lang.Save;

        /// <summary>
        ///   查找类似选择的本地化字符串
        /// </summary>
		public string Select => Lang.Select;

        /// <summary>
        ///   查找类似停止的本地化字符串
        /// </summary>
		public string Stop => Lang.Stop;

        /// <summary>
        ///   查找类似示教的本地化字符串
        /// </summary>
		public string Teach => Lang.Teach;

        /// <summary>
        ///   查找类似确定示教点的本地化字符串
        /// </summary>
		public string TeachConfirmString => Lang.TeachConfirmString;

        /// <summary>
        ///   查找类似三的本地化字符串
        /// </summary>
		public string Three => Lang.Three;

        /// <summary>
        ///   查找类似时间的本地化字符串
        /// </summary>
		public string Time => Lang.Time;

        /// <summary>
        ///   查找类似二的本地化字符串
        /// </summary>
		public string Two => Lang.Two;

        /// <summary>
        ///   查找类似更新的本地化字符串
        /// </summary>
		public string Update => Lang.Update;


        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName) =>
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }

    public class LangKeys
    {
        /// <summary>
        ///   查找类似添加的本地化字符串
        /// </summary>
		public static string Add = nameof(Add);

        /// <summary>
        ///   查找类似轴XY的本地化字符串
        /// </summary>
		public static string AxisXY = nameof(AxisXY);

        /// <summary>
        ///   查找类似相机的本地化字符串
        /// </summary>
		public static string Camera = nameof(Camera);

        /// <summary>
        ///   查找类似取消的本地化字符串
        /// </summary>
		public static string Cancel = nameof(Cancel);

        /// <summary>
        ///   查找类似确定的本地化字符串
        /// </summary>
		public static string Confirm = nameof(Confirm);

        /// <summary>
        ///   查找类似日期的本地化字符串
        /// </summary>
		public static string Date = nameof(Date);

        /// <summary>
        ///   查找类似调试的本地化字符串
        /// </summary>
		public static string Debug = nameof(Debug);

        /// <summary>
        ///   查找类似删除的本地化字符串
        /// </summary>
		public static string Delete = nameof(Delete);

        /// <summary>
        ///   查找类似显示的本地化字符串
        /// </summary>
		public static string Display = nameof(Display);

        /// <summary>
        ///   查找类似编辑的本地化字符串
        /// </summary>
		public static string Edit = nameof(Edit);

        /// <summary>
        ///   查找类似四的本地化字符串
        /// </summary>
		public static string Four = nameof(Four);

        /// <summary>
        ///   查找类似帮助的本地化字符串
        /// </summary>
		public static string Help = nameof(Help);

        /// <summary>
        ///   查找类似序号的本地化字符串
        /// </summary>
		public static string Index = nameof(Index);

        /// <summary>
        ///   查找类似输入的本地化字符串
        /// </summary>
		public static string Input = nameof(Input);

        /// <summary>
        ///   查找类似查找类似{0}的本地化字符串的本地化字符串
        /// </summary>
		public static string LangComment = nameof(LangComment);

        /// <summary>
        ///   查找类似语言的本地化字符串
        /// </summary>
		public static string Language = nameof(Language);

        /// <summary>
        ///   查找类似列表的本地化字符串
        /// </summary>
		public static string List = nameof(List);

        /// <summary>
        ///   查找类似手动的本地化字符串
        /// </summary>
		public static string Manual = nameof(Manual);

        /// <summary>
        ///   查找类似运动的本地化字符串
        /// </summary>
		public static string Move = nameof(Move);

        /// <summary>
        ///   查找类似名称的本地化字符串
        /// </summary>
		public static string Name = nameof(Name);

        /// <summary>
        ///   查找类似一的本地化字符串
        /// </summary>
		public static string One = nameof(One);

        /// <summary>
        ///   查找类似打开的本地化字符串
        /// </summary>
		public static string Open = nameof(Open);

        /// <summary>
        ///   查找类似操作的本地化字符串
        /// </summary>
		public static string Operate = nameof(Operate);

        /// <summary>
        ///   查找类似其他的本地化字符串
        /// </summary>
		public static string Other = nameof(Other);

        /// <summary>
        ///   查找类似点位的本地化字符串
        /// </summary>
		public static string Position = nameof(Position);

        /// <summary>
        ///   查找类似料号的本地化字符串
        /// </summary>
		public static string ProductNum = nameof(ProductNum);

        /// <summary>
        ///   查找类似属性的本地化字符串
        /// </summary>
		public static string Property = nameof(Property);

        /// <summary>
        ///   查找类似备注的本地化字符串
        /// </summary>
		public static string Remark = nameof(Remark);

        /// <summary>
        ///   查找类似运行的本地化字符串
        /// </summary>
		public static string Run = nameof(Run);

        /// <summary>
        ///   查找类似保存的本地化字符串
        /// </summary>
		public static string Save = nameof(Save);

        /// <summary>
        ///   查找类似选择的本地化字符串
        /// </summary>
		public static string Select = nameof(Select);

        /// <summary>
        ///   查找类似停止的本地化字符串
        /// </summary>
		public static string Stop = nameof(Stop);

        /// <summary>
        ///   查找类似示教的本地化字符串
        /// </summary>
		public static string Teach = nameof(Teach);

        /// <summary>
        ///   查找类似确定示教点的本地化字符串
        /// </summary>
		public static string TeachConfirmString = nameof(TeachConfirmString);

        /// <summary>
        ///   查找类似三的本地化字符串
        /// </summary>
		public static string Three = nameof(Three);

        /// <summary>
        ///   查找类似时间的本地化字符串
        /// </summary>
		public static string Time = nameof(Time);

        /// <summary>
        ///   查找类似二的本地化字符串
        /// </summary>
		public static string Two = nameof(Two);

        /// <summary>
        ///   查找类似更新的本地化字符串
        /// </summary>
		public static string Update = nameof(Update);

    }
}